import { Injectable } from '@angular/core';

import { Http, Headers, URLSearchParams, RequestOptions, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';

@Injectable()
export class NotificationListService {
    private notificationDeleteUrl: string = '/water/boards/delete';
    constructor(private http: Http) { }

    deleteNotification(ids: string[]): Promise<any> {
        let headers = new Headers({'Content-Type': 'application/json'});
        let options = new RequestOptions({headers: headers});
        return this.http.post(this.notificationDeleteUrl, JSON.stringify({'ids': ids}), options)
        .toPromise().then(resp => resp.json() || {}).catch(this.handleError);
    }

    handleError(error: Response | any) {
    let errMsg: string;

    if (error instanceof Response) {
      const body = error.json() || '';
      const err = body.description || JSON.stringify(body);
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    return Promise.reject(errMsg);
  }
}
